﻿using System;
using System.Collections.Generic;
using System.Text;

namespace RedisHelper.MailCode
{
    public class Code
    {
        /// <summary>
        /// 保存验证码
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public bool InsertCode(string mail, string code)
        {
            using (RedisHelper th = new RedisHelper())
            {
                return th.GetDatabase(1).StringSet(mail + "_Code", code, TimeSpan.FromMinutes(30));
            }
        }

        /// <summary>
        /// 查找验证码
        /// </summary>
        /// <param name="mail"></param>
        /// <returns></returns>
        public string SelectCode(string mail)
        {
            using (RedisHelper th = new RedisHelper())
            {
                var data = th.GetDatabase(1).StringGet(mail + "_Code");
                if (data.IsNull)
                    return null;
                return data.ToString();
            }
        }
    }
}
